package cn.edu.neu.vmmigeval.cloud.util;

import cn.edu.neu.vmmigeval.cloud.entity.DataCenter;
import cn.edu.neu.vmmigeval.cloud.entity.Host;
import cn.edu.neu.vmmigeval.cloud.entity.Vm;
import cn.edu.neu.vmmigeval.cloud.policy.VmAllocation;
import cn.edu.neu.vmmigeval.cloud.policy.impl.*;
import cn.edu.neu.vmmigeval.cloud.policy.mgrdsm.MigratedHostPolicyMGSM;
import cn.edu.neu.vmmigeval.cloud.policy.mgrdsm.VmPlacementPolicyMGSM;
import cn.edu.neu.vmmigeval.cloud.policy.mgrdsm.VmSelectionPolicyMGSM;

/**
 * Created by yfwz100 on 16/2/25.
 */
public class HostUtil {

    public static boolean isSuitableForVm(Vm vm, Host host) {
        return false;
    }

    public static VmAllocation getVmAllocation(String name, double highThreshold, DataCenter datacenter) {

        VmAllocation vmAllocation = null;
        if (name.equals("DTDT")) {
            vmAllocation = new VmAllocation(
                    new MigratedHostPolicyDoubleThreshold(),
                    new VmSelectionPolicyMU(),
                    new VmPlacementPolicyPABFD(new MigratedHostPolicyDoubleThreshold()));
        } else if (name.equals("IMP")) {
            vmAllocation = new VmAllocation(
                    new MigratedHostPolicyInterQuartileRange(),
                    new VmSelectionPolicyMinimumMigrationTime(),
                    new VmPlacementPolicyPABFD(new MigratedHostPolicyDoubleThreshold()));
        } else if (name.equals("OFIF")) {
            vmAllocation = new VmAllocation(
                    new MigratedHostPolicyStaticThreshold(highThreshold),
                    new VmSelectionPolicyMinimumMigrationTime(),
                    new VmPlacementPolicyOptimal());
        } else if (name.equals("MGRDSM")) {
            vmAllocation = new VmAllocation(
                    new MigratedHostPolicyMGSM(),
                    new VmSelectionPolicyMGSM(),
                    new VmPlacementPolicyMGSM(datacenter.getHosts(), new MigratedHostPolicyMGSM()));
        }

        return vmAllocation;
    }
}
